$(function(){

    $('a[rel="roll"]').click(function(){
        var cachePreventer = new Date().getTime();
        
        /* JS way */
        console.time('Roll');
        var lowerValue = 2;
        var upperValue = 12;
        var attack = parseInt($('#attack').val());
        var defense = parseInt($('#defense').val());
        var roll = parseInt(Math.floor((upperValue - (lowerValue-1)) * Math.random()) + lowerValue);
        var result = ((attack + roll) >= defense) ? 'Hit' : 'Miss';        
        $('#roll-result').empty().html(result);
        console.timeEnd('Roll');
        
        /* Ajax way
        $.post('roll.php?cache='+cachePreventer,{attack:$('#attack').val(),defense:$('#defense').val()},function(response) {
            $('#roll-result').html(response);
        });*/
    });
    
});